package com.crl.ssc.dic.service;

import com.cars.util.global.GlobalOperaCode;
import com.cars.util.list.ListUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.crl.ssc.dic.dao.DicCityDao;
import com.crl.ssc.dic.dto.DicCityDTO;
import com.crl.ssc.dic.model.DicCity;
import com.crl.ssc.dic.vo.DicCitySearchVO;
import java.util.List;

/**
 * @description: 字典管理-城市字典Service
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020-08-03 18:38:21
 */
@Service
public class DicCityService {
    @Autowired
    private DicCityDao dicCityDao;
    /**
     * 增加
     *
     * @param dicCityDTO
     * @return
     */
    public int add(DicCityDTO dicCityDTO) {
        DicCity dicCity = new DicCity();
        BeanUtils.copyProperties(dicCityDTO, dicCity);
        return dicCityDao.add(dicCity);
    }
    /**
     * 修改
     *
     * @param dicCityDTO
     * @return
     */
    public int update(DicCityDTO dicCityDTO) {
        DicCity dicCity = new DicCity();
        BeanUtils.copyProperties(dicCityDTO, dicCity);
        return dicCityDao.update(dicCity);
    }
    /**
     * 删除
     *
     * @param cityCode
     * @return
     */
    public int delete(String cityCode) {
        DicCity dicCity = dicCityDao.get(cityCode);
        if (dicCity  == null) {
           return GlobalOperaCode.OPERA_NOT_EXIST;
         } else {
           return dicCityDao.delete(cityCode);
         }
    }

    /**
     * 列表
     *
     * @param dicCitySearchVO
     * @return
     */
    public List<DicCityDTO> list(DicCitySearchVO dicCitySearchVO) {
        List<DicCity> list = dicCityDao.list(dicCitySearchVO);
        List<DicCityDTO> listResult = ListUtils.copyList(list, DicCityDTO.class);
        return listResult;
    }
    /**
     * 记录条数
     *
     * @param dicCitySearchVO
     * @return
     */
    public int count(DicCitySearchVO dicCitySearchVO) {
        return dicCityDao.count(dicCitySearchVO);
    }
    /**
     * 获取单个
     *
     * @param cityCode
     * @return
     */
    public DicCityDTO get(String cityCode) {
        DicCity dicCity = dicCityDao.get(cityCode);
        DicCityDTO dicCityDTO = new DicCityDTO();
        BeanUtils.copyProperties(dicCity, dicCityDTO);
        return dicCityDTO;
    }
}
